import { fromJS } from 'immutable'
import * as actionTypes from './actionTypes'

const defaultState = fromJS({//immutable对象
    topicList:[],
    articleList:[],
    recommendList: [],
    articlePage: 1,
    showScroll: false,
});

const reduce = (state = defaultState, action) => {
    switch (action.type) {
        case actionTypes.CHANGE_HOME_DATA:
          return state.merge({
            topicList: fromJS(action.topicList),
            articleList: fromJS(action.articleList),
            recommendList: fromJS(action.recommendList)
        }); 
        case actionTypes.ADD_LIST:
            return state.merge({
                articleList: state.get('articleList').concat(action.addartlist),
                articlePage: action.nextPage
            });
        case actionTypes.TOGGLE_SCROLL_TOP:
            return state.set('showScroll',action.show)
        default:
            return state;
    }

    
}

export default reduce;